<?php

echo "test";
	function Query($sql)
	{
		$conn = mysql_connect("localhost:3306","root","") or die("Loi ket noi!");
		mysql_select_db("test") or die ("Loi CSDL!");
		$rows =mysql_query($sql, $conn) or die("Loi truy van!");
		mysql_close($conn);
		return $rows;	
	}
	
	if(isset($_GET['action']))
	{
		$action = $_GET['action'];	
	} else $action ="";

	if(isset($_GET['id']))
	{
		$id = $_GET['id'];	
	} else $id ="";


?>

<html>
<body>

<?php

	switch ($action){

	case "new":?>
<form action="test.php?action=insert" method="POST">
		<table>
<tr>
<td>Question:</td>
<td><textarea name="question"> </textarea></td>
</tr>

<tr>
<td>Solution 1:</td>
<td><textarea name="solution_1"> </textarea></td>
</tr>

<tr>
<td>Solution 2:</td>
<td><textarea name="solution_2"> </textarea></td>
</tr>

<tr>
<td>Solution 3:</td>
<td><textarea name="solution_3"> </textarea></td>
</tr>

<tr>
<td>Solution 4:</td>
<td><textarea name="solution_4"> </textarea></td>
</tr>
<tr>

<td><input type="submit" value="Them"></td>
<td><input type="reset" value="Nhap lai"></td>
</tr>


		
</table>
</form>
<?php
	break;	
	case "edit":
	break;	
	case "delete":
	break;	
	case "insert":
		$q = $_POST['question'];
		$sol_1 = $_POST["solution_1"];
		$sol_2 = $_POST["solution_2"];
		$sol_3 = $_POST["solution_3"];
		$sol_4 = $_POST["solution_4"];
 $sql = "insert into question (question, solution_1, solution_2, solution_3, solution_4) values ('".$q."','".$sol_1."','".$sol_2."','".$sol_3."','".$sol_4."')";
		//die(":::::>".strlen($sql)."<:::::");
//$sql = "insert into question (question) values ('".$q."')";
				
Query($sql);
		header("location:test.php");
		
	break;	
	case "update":
	break;	
	}

?>



<a href="test.php?action=new">Them cau hoi</a><br>

<?php

	$rows = Query("Select * from Question");
	while($row = mysql_fetch_array($rows))
	{
		echo "Cau hoi ".$row["id"]."<br>";
		echo $row['question']."\n";
		echo "A. ".$row['solution_1']."<br>";
		echo "B. ".$row['solution_2']."<br>";
		echo "C. ".$row['solution_3']."<br>";
		echo "D. ".$row['solution_4']."<br>";

		echo "<br>";	
	}	
	
?>

</body>

</html>


